<?php
class SetTpl extends Action {
	/* (non-PHPdoc)
	 * @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );
		$type = rqst ( 'type' );
		$thid = irqst ( 'thid' );
		$tpid = irqst ( 'tpid' );
		$tpl ['template_file'] = rqst ( 'tpl' );
		
		$data = array ('success' => false );
		$tpM = new WebTemplateModel ();
		
		if ($tpid) { //修改
			$rst = $tpM->update ( $tpl, $tpid );
		} else if ($type && $thid) {
			$tpl ['page_type'] = $type;
			$tpl ['theme_id'] = $thid;
			$rst = $tpM->insert ( $tpl );
		}
		if ($rst) {
			$data ['success'] = true;
			$data ['tpid'] = $rst ['template_id'];
		} else {
			$data ['msg'] = '在设置模板的过程中出错了错误:' . $tpM->last_error_msg ();
		}
		return new JsonView ( $data );
	}
}